import router from "./index.js";

// 所有路由：

const allRoutes = [
    {
        id:"1",
        name: "CRUD",
        path: "CRUD",
        component: () => import("../views/CRUD/index.vue")
    },
    {
        id: "2",
        name: "piniademo",
        path: "piniademo",
        component: () => import("../views/piniaDemo/index.vue")
    },
    {
        id: "3",
        name: "Operator",
        path: "Operator",
        component: () => import("../views/Operator/index.vue")
    },
    {
        id: "4-1",
        name: "Lifecycle",
        path: "Lifecycle_options",
        component: () => import("../views/Lifecycle/Lifecycle_options.vue"),

    },
    {
        id: "4-2",
        name: "Lifecycle_composition",
        path: "Lifecycle_composition",
        component: () => import("../views/Lifecycle/Lifecycle_composition.vue")

    },
    {
        id: "4-3",
        name: "Lifecycle_ParentSon",
        path: "Lifecycle_ParentSon",
        component: () => import("../views/Lifecycle/Lifecycle_ParentSon/Parent.vue"),
    },
    {
        id: "5-1",
        name: "ParentToSon",
        path: "ParentToSon",
        component: () => import("../views/ComponentChuan/ParentToSon/Parent.vue")
    },
    {
        id: "5-2",
        name: "Brother",
        path: "Brother",
        component: () => import("../views/ComponentChuan/Brother/index.vue")
    },
    {
        id: "5-3",
        name: "TransferValueDemo",
        path: "TransferValueDemo",
        component: () => import("../views/ComponentChuan/demo/index.vue")
    },
    {
        id: "5-4",
        name: "TransferValueDemo02",
        path: "TransferValueDemo02",
        component: () => import("../views/ComponentChuan/demo02/index.vue")
    },
    {
        id: "5-5",
        name: "refdemo",
        path: "refdemo",
        component: () => import("../views/ComponentChuan/refdemo/Parent.vue")
    },
    {
        id: "5-6",
        name: "refdemo02",
        path: "refdemo02",
        component: () => import("../views/ComponentChuan/refdemo02/Parent.vue")
    },
    {
        id: "5-7",
        name: "providerAndInject",
        path: "providerAndInject",
        component: () => import("../views/ComponentChuan/providerAndInject/Parent.vue")
    },
    {
        id: "6-1",
        name: "List",
        path: "List",
        component: () => import("../views/routeChuan/params/List.vue")
    },
    {
        name: "Detail",
        path: "Detail/:id",
        component: () => import("../views/routeChuan/params/Detail.vue")
    },
    {
        id: "6-2",
        name: "List02",
        path: "List02",
        component: () => import("../views/routeChuan/query/List.vue")
    },
    {
        name: "Detail02",
        path: "Detail02",
        component: () => import("../views/routeChuan/query/Detail.vue")
    },
    {
        id: "7-1",
        name: "vuexdemo01",
        path: "vuexdemo01",
        component: () => import("../views/vuexdemo/index.vue")
    },
    {
        id: "7-2",
        name: "vuexdemo02",
        path: "vuexdemo02",
        component: () => import("../views/vuexdemo/goods.vue")
    },
]

// 过滤当前用户的路由配置

export const getCurrentUserRoutes = () => {

    // 1、获取当前用户的权限：checkedKeys
    //["1","4-1","4-2","4-3"]
    const checkedKeys = JSON.parse(sessionStorage.getItem("checkedKeys"));

    // 2、过滤：
    const currentRoutes = allRoutes.filter(item =>checkedKeys.includes(item.id));

    // 添加对应的路由配置: addRoute;
    currentRoutes.forEach(item => {
        router.addRoute("Admin", item)
    })
    console.log("router.getRoutes()", router.getRoutes());
    // return allRoutes;
}